﻿/*****Game channel created at 2008-08-31 by onemax*********************************************************/
Pui.combo={        
		afterCreate:function(){
			var doc=document;
			var docElement=doc.documentElement;
			var sHeight=docElement.clientHeight;
			var dH=docElement.scrollHeight>sHeight?docElement.scrollHeight:sHeight;
			var scH=docElement.scrollTop>=0?(docElement.scrollTop+sHeight/2):sHeight;
			var h=scH-$(".up_1").height()/2;
			var w=docElement.clientWidth/2-$(".up_1").width()/2;
			$(".uper").height(dH).show();
			$(".up_1").css({top:h,left:w}).show();
			return false;

		},
		closeDiv:function(){
			$(".uper").hide();
			$(".up_1").hide();
		},
		checkIds:function(path){
			var arr=$(""+path+" input:checked");
			var ids='';
			if(arr.length==0)
			{
				alert("您还没有选择");
				return
			}		
			for(var i=0;i<arr.length;i++){
				if(i==0) ids=arr.eq(i).attr("id")
				else ids+=','+arr.eq(i).attr("id");
			}
			return ids;
		},
		Addpage:function(addtype,unionID){
			document.getElementById("AddSrc").src='http://www.pomoho.com/game/union/addunioncontent.aspx?id=0&type='+addtype+'&curpage=1&uid='+unionID;
			Pui.combo.afterCreate();
		},
		addDom:function(){
			if(!$("#sendMsg").length)
			{
				$('#Prompt h3').after('<p id="sendMsg" class="p1"></p>');
				$('#btnlog').after('<input id="Back" class="back" type="button" value="确 定" />&nbsp;&nbsp;<input id="ibtn_f2" class="back" type="button" value="关 闭" />');
				$("#ibtn_f2").bind("click",Pui.combo.closeMsgDiv);
			}

		}								
};
Pui.showData=function (json){;
		var path={
			user:['.t_login span','.c_friend span','.c_fans span','.c_view span','.c_video span','.c_flower span'],video:['.c_view span','.c_review span','.c_bookmark span'],special:['.c_video span','.c_view span','.c_rss span','.t_update span','.t_length span'],combo:['.d_video span','.d_collect span','.d_topic span','.d_menber span','.d_album span','.d_mvvideo span','.d_view span'],combo_handle:['.c_num','.c_num_m']
		};
		var path_n={
			user:['.d_time_login span','.d_friend span','.d_fans span','.d_view span','.d_video span','.d_flower span'],video:['.d_view span','.d_review span','.d_bookmark span'],special:['.d_video span','.d_view span','.d_rss span','.d_update span','.d_length span'],combo:['.d_video span','.d_collect span','.d_topic span','.d_menber span','.d_album span','.d_mvvideo span','.d_view span']
		};
		for(var i=0,length=json.length;i<length;i++){
			var type=json[i].type,id=json[i].id,data=json[i].data,wrap='#'+type+'_'+id;
			if(!$(wrap)[0])continue;
			for(j=0;j<path[type].length;j++){
				if($(wrap+' '+path[type][j])[0]){
					$(wrap+' '+path[type][j])[0].innerHTML=data[j];
					
				}else if($(wrap+' '+path_n[type][j])[0]){
					$(wrap+' '+path_n[type][j])[0].innerHTML=data[j];
					
				}
			}
		}
	}; 
	
//会员报道
function f_checkin()
{
	var result = gupub.MemberCheckIn(_gameunion.unionid,_user.uid).value;
	if ( result.length > 0 )
	{
		var code = result.substr(0,1);
		if ( code == 1 )
		{
			$("#p_checkin").hide();
			alert("报道成功");
			var s = "<li><span class=\"fleft title\">";
			s += "<a href=\"http://home.pomoho.com/"+_user.spaceurl+".shtml\" title=\""+_user.nick+"\" target=\"_blank\">"+_user.nick+"  来此报到</a></span>";
			s += "<span class=\"fright date\">"+Pui.ui.gettime().substr(0,9)+"</span></li>";
			$(s).prependTo('#ul_clearfix');
		}
		else if (code==2)
		{
			alert("报到失败,你不是该公会的成员!");
		}
		else
		{
			alert("报到失败"+result.substr(1));
		}
	}
}
//公会留言
function f_sendMessage()
{
	if ( $("#text_message").val() == "" )
	{
		alert("留言不可以为空!");
		$("#text_message").focus();
		return false;
	}
	else if( $("#text_message").val().codeLength() > 3000 )
	{
		alert("留言过长!");
		$("#text_message").focus();
		return false;
	}
	var attitude = $("input[name='rad_Attitude'][checked]").val();
	var attitudeName = "中立"
	if (attitude==1)
	{attitudeName="友好";}
	else if (attitude==3)
	{attitudeName="敌对";}
	Pui.loadScript("http://www.pomoho.com/do/game/gameinterface.aspx?type=1&userid="+_user.uid+"&unionid="+_gameunion.unionid+"&attitude="+attitude+"&content="+escape($("#text_message").val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->").replace("\n", " ")));
	var u = _is_login ? '<a href="javascript:;">'+_user.nick+'</a>' : '游客';
		var tempHtml = "<div class=\"guester clearfix\"><img alt=\"\" src=\"http://static.pomoho.com/static/images/photo_68.gif\"/>";
		tempHtml += "<dl><dt><span class=\"left\"><span class=\"fleft\">"+u+"</span><span class=\"fright\">";
		tempHtml += "<a href=\"#\">"+attitudeName+"</a></span></span><span class=\"fright\">"+Pui.ui.gettime()+" ";
		tempHtml += "<a href=\"javascript:f_quote(0)\">回复</a></span></dt>";
		tempHtml += "<dd id=\"dd_0\">"+$("#text_message").val().replace(/\[quote\]/g,"<div class='commentQuote'>").replace(/\[\/quote\]/g,"</div>")+"</dd></dl></div>";
		$(tempHtml).prependTo('#div_guestbook');
		//$("#text_message").val("http://www.pomoho.com/do/game/gameinterface.aspx?type=1&userid="+_user.uid+"&unionid="+_gameunion.unionid+"&attitude="+attitude+"&content="+escape($("#text_message").val()));
}
//发表回调
function sendcallback(msg)
{
	var result = msg.substr(0,1);
	if (result==1)
	{
		alert("发表成功!");
		$("#text_message").focus();
		$("#text_message").val("");
	}
	else
	{
		alert("发表失败"+result.substr(1));
		$("#text_message").focus();
		$("#text_message").val("");
	}
}
//引用
function f_quote(id)
{
	var id = "#dd_"+id;
	var cotents = +$(id).html();
	$("#text_message").val("[quote]引用："+$(id).html().replace(/\<DIV class=commentQuote\>/g,"[quote]").replace(/\<\/DIV\>/g,"[/quote]")+"[/quote]");
	$("#text_message").focus();
}
//add for friend
function f_addfriend(userid)
{
	if(_is_login)
	{
		Pui.loadScript(baseurl+"/space/personjs.aspx?dotype=1&userid="+userid+"");
		if(typeof(_userid)!='undefined') _userid=null;
	}else{		
		flag=3;
		_userid=userid;
		Pui.newSH.loginfo();

	}	
}
//add by xiangmz 为兼容 comboid=unionID,objID=userID
function f_comboInterFace(otype,atype,comboid,objid)
{
	if ( otype=="add"&&!_is_login )
	{
			flag=4;
			addPram={otype:otype,atype:atype,comboid:comboid};
			Pui.newSH.loginfo();
	}else{
			Pui.loadScript("http://www.pomoho.com/game/union/joinunion.aspx?type="+otype+"&guid="+comboid+"&uid="+_user.uid);	
			//Pui.loadScript("http://www.pomoho.com/game/union/joinunion.aspx?type="+otype+"&guid="+comboid+"&uid="+objid);	
	}
}
function addCallBack(code,msg)
{
	alert(msg);
	window.location.reload();
}
//add by xiangmz
String.prototype.codeLength=function(){
	 var len=0;
	 if(this==null||this.length==0)
	  return 0;
	 var str=this.replace(/(^\s*)|(\s*$)/g,"");//去掉空格
	 for(i=0;i<str.length;i++)
	  if(str.charCodeAt(i)>0&&str.charCodeAt(i)<128)
	   len++;
	  else 
	   len+=2;
	 return len;
} 
$.fn.check = function(mode){
   var mode = mode || 'on'; //default
    return this.each(function(){
        switch(mode){
            case 'on':
                this.checked = true;
                break;
            case 'off':
                this.checked = false;
                break;
            case 'toggle':
            	if(this.disabled==false)
                this.checked = !this.checked;
                break;
        }
    });
};

$(function(){
	if($("#checkall").length){
		$("#checkall").click(function(){
			$(".addList input:checkbox").check('on');
		});
	}
		if($("#checkoff").length){
		$("#checkoff").click(function(){
			$(".addList input:checkbox").check('toggle')
		});
	}

});
